package com.superc.lib.ui;

import com.superc.R;
import com.superc.lib.helper.KeyValue;
import com.superc.lib.helper.ResourceHelper;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.View;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

public class UIFunction{
	
	public static Spinner createSpinnerFromResource(Activity view,int comboboxID,int arrResource ){
		Spinner combobox=(Spinner)view.findViewById(comboboxID);
    	ArrayAdapter<CharSequence> dataAdapter=ArrayAdapter.createFromResource(view, 
    			arrResource, android.R.layout.simple_spinner_item);
    	dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    	combobox.setAdapter(dataAdapter);
    	return combobox;
	}
	
	
	public static <TK,TV> Spinner createSpinnerFromArray(Activity view,int comboboxID,KeyValue<TK,TV>[] arrData ){
		Spinner combobox=(Spinner)view.findViewById(comboboxID);
		KeyValueArrayAdapter<TK,TV> dataAdapter=new KeyValueArrayAdapter<TK,TV>(view, android.R.layout.simple_spinner_item,
    			arrData);
    	dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    	combobox.setAdapter(dataAdapter);
    	return combobox;
	}
	
	public static RadioGroup getRatioGroup(Activity view,int id){
		return (RadioGroup)view.findViewById(id);
	}
	
	public static RadioButton getRatioButton(Activity view,int id){
		return (RadioButton)view.findViewById(id);
	}
	
	public static EditText getEditText(Activity view,int id){
		return (EditText)view.findViewById(id);
	}
	
	public static CheckBox getCheckbox(Activity view,int id){
		return (CheckBox)view.findViewById(id);
	}
	
	public static Button getButton(Activity view,int id){
		return (Button)view.findViewById(id);
	}
	
	public static ListView getListView(Activity view,int id){
		return (ListView)view.findViewById(id);
	}
	
	public static TextView getTextView(Activity view,int id){
		return (TextView)view.findViewById(id);
	}
	
	public static TextView getTextView(View view,int id){
		return (TextView)view.findViewById(id);
	}
	
	public static ImageButton getImageButton(Activity view,int id){
		return (ImageButton)view.findViewById(id);
	}
	
	public static WebView getWebView(Activity view,int id){
		return (WebView)view.findViewById(id);
	}
	
	public static ImageView getImageView(View view,int id){
		return (ImageView)view.findViewById(id);
	}
	
	public static void ShowMessage(Context context,String title,String message){
		Builder dialog=new AlertDialog.Builder(context);
		dialog.setTitle(title);
		dialog.setMessage(message);
		dialog.setPositiveButton(ResourceHelper.getString(context,R.string.strAlertPositionText),
				new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						
					}
					
				});
		dialog.show();
	}
}
